<?php
include_once 'UserErrors.php';


class User
{
	protected $_user_id;
	protected $_user_email;
	protected $_user_password;

	public function __construct($user_id)
	{
		$user_record = self::_getUserRecord($user_id);
		$this->_user_id 		= $user_record['id'];
		$this->_user_email 	= $user_record['email'];
		$this->_user_password = $user_record['password'];
	}

	//we'll fill these in later
	public function __get($value) {
	}
	public function __set($name, $value) {
	}

	private static function _getUserRecord($user_id)
	{
		$user_id = self::_validateUserId($user_id);
		//For this tutorial, we'll use a mock-up record to represent retrieving the record
		//from the database and returning the data
		$user_record = array();
		switch($user_id) {
			case 1:
				$user_record['id'] = 1;
				$user_record['email'] = 'nikko@example.com';
				$user_record['password'] = 'i like croissants';
				break;

			case 2:
				$user_record['id'] = 2;
				$user_record['email'] = 'john@example.com';
				$user_record['password'] = 'me too!';
				break;

			case 'error':
				//simulates an unknown exception from whatever SQL library is being used:
				throw new Exception('An error from the SQL library!');
				break;
		}

		 
		return $user_record;
	}
	 
	 
	 
	private static function _validateUserId($user_id) {
		if( !is_numeric($user_id) && $user_id != 'error' ) {
			throw new Exception('Whoa! I think there\'s something wrong with the user id', UserErrors::INVALIDID);
		}
		return $user_id;
	}
	 
	 
	 
	 
}
?>